package dao

import (
	"fmt"
	"github.com/jinzhu/gorm"
)

type FilterProductCatalog struct {
	Id            int64  `gorm:"primaryKey"`
	CatalogNo     string `gorm:"column:catalogNo;type:varchar(255)"`
	FigBranchNo   string `gorm:"column:figBranchNo;type:varchar(255)"`
	FigName       string `gorm:"column:figName;type:varchar(255)"`
	IllustNo      string `gorm:"column:illustNo;type:varchar(255)"`
	IllustFileURL string `gorm:"column:illustFileURL;type:varchar(255)"`
	productId     int64  `gorm:"column:productId;type:bigint(20)"`
}

type FilterProductCatalogDao struct {
	db *gorm.DB
}

func NewFilterProductCatalogDao(db *gorm.DB) *FilterProductCatalogDao {
	return &FilterProductCatalogDao{db: db}
}

func (f *FilterProductCatalogDao) CreateFilterProductCatalog(param *FilterProductCatalog) int64 {
	err := f.db.Create(param).Error
	if err != nil {
		fmt.Print("写入 FilterProductCatalog db错误", err)
	}
	return param.Id
}

func (f *FilterProductCatalogDao) GetListByProductId(productId string) []*FilterProductCatalog {
	res := make([]*FilterProductCatalog, 0)
	f.db.Where("productId = ?", productId).Find(&res)
	return res
}
